#!/bin/bash

if [ $# -lt 1 ]; then
   echo "$0 <git url>"
   exit 1
fi

url=$1
if [[ $url =~ "https://" ]]; then
	prj=${url##*/}
	prj=${prj%.git}
else
	prj=$url
	url="https://gitee.com/src-openeuler/${url}.git"
fi
rm -rf "$prj"
osc co "$prj"
if [ $? -ne 0 ]; then
  echo "adding project: $prj"
  osc mkpac $prj
else 
  echo "fixing project: $prj"
fi

sed "s|URL|${url}|g" service.template > ${prj}/_service
osc add ${prj}/_service
osc ci ${prj} -m "add ${prj}"
